package com.yanghang.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
public class UploadController {
    @Value("${imgpath}")
    private String path;
    @PostMapping("/upload")
    public Map<String,Object >upload(MultipartFile mf) throws IOException {
       String newFileName= UUID.randomUUID().toString()+mf.getOriginalFilename();
       mf.transferTo(new File(path,newFileName));
       Map<String,Object>map=new HashMap<>();
       map.put("code",2);
       map.put("flag",true);
       return map;
    }
}
